package com.etennis.listener;
import com.etennis.exception.SystemException;
import com.etennis.pojos.message.ExchangeMessage;
import com.etennis.service.IOrderService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class FanoutListener {
    private static final ObjectMapper objectMapper = new ObjectMapper();
    @Autowired
    private IOrderService orderService;
    @RabbitListener(queues = "demo.quenue")
    public void listenExchange(String message) {
        try {
            ExchangeMessage exchangeMessage = objectMapper.readValue(message, ExchangeMessage.class);
            orderService.exchange(exchangeMessage.getCommodityId(),exchangeMessage.getMemberId());

        } catch (JsonProcessingException e) {
           e.printStackTrace();
        }
    }

}